<?php

class RestV9
{
	
  // public myspaceContext
   
    public $context = NULL;
  
  /**
   * Sets up the Rest V9 with MySpace Context
   *
   * @param MySpaceContext $context
   * @return object a new restv9 object
   */
    
   public function __construct($context)  {
     $this->context = $context;
   }
   
   /*
   *  OpenSocial v0.9 ProfileComments
   *  Resource: http://opensocial.myspace.com/roa/09/profilecomments/@me/@self
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_ProfileComments
   *  Description: Get the User Profile Comments
   *  @param mixed  $personId  current Person Id
   *  @param string $fields    By default, the id of the comment author will be added to the result set, 
   *  						   give the fields=author to get more information on the author
   *  @return object of php object representing the JSON which is list of the current user's profile comments
   */
 
  public function getProfileComments($personId, $fields = NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/profilecomments/'.$personId.'/@self?';
    $params = array('format'=>'json', 'fields'=>'@all', 'fields'=>$fields);
	
  	$responseJSON = $this->context->call($REST,$params, 'GET');
 
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);
  }

   /*
   *  OpenSocial v0.9 Ablums
   *  Resource: http://opensocial.myspace.com/roa/09/albums/@supportedFields
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Albums
   *  Description:  Get Album Supported Fields
   *  @return object of php object representing the JSON which is list of the album supported fields
   */ 
  
  public function getAlbumsSupportedFields(){
    $REST  = 'http://opensocial.myspace.com/roa/09/albums/@supportedFields?';
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 Ablums
   *  Resource: http://opensocial.myspace.com/roa/09/albums/@me/@self
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Albums
   *  Description:  Get user albums
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        set the specific fields here
   *  @return object of php object representing the JSON which is list of the current user's albums
   */
  
   public function getAlbums($personId, $startIndex=1, $count=20, $fields=NULL){
  	 $REST = "http://opensocial.myspace.com/roa/09/albums/".$personId."/@self?";
  	 $params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json'
  				);



  	 $responseJSON = $this->context->call($REST,$params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	 return MySpaceUtils::parseJSON($responseJSON);
  }
  
  /*
   *  OpenSocial v0.9 Ablums
   *  Resource: http://opensocial.myspace.com/roa/09/albums/@me/@self/{albumId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Albums
   *  Description:  Get user album By Album  Id
   *  @param mixed   $personId      current Person Id
   *  @param string  $ablumId	    album id of the album
   *  @param string  $fields        set the specific fields here
   *  @return object of php object representing the JSON which is list of the specific user album
   */
  
  public function getAlbum($personId, $albumId, $fields=NULL){

  	$REST = "http://opensocial.myspace.com/roa/09/albums/".$personId."/@self/".$albumId.'?';
  	$params = array('format'=>'json', 'fields'=>'@all', 'fields'=>$fields);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Ablums
   *  Resource: http://opensocial.myspace.com/roa/09/albums/@me/@self/{albumId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Albums
   *  Description:  Add the Album
   *  @param mixed   $personId      current Person Id
   *  @param string  $caption	    title of the album
   *  @param string  $private       privacy 'EveryOne | FriendsOnly | Me'
   *  @param string  $location      location of the album
   *  @return object of php object representing the url of the newly created album
   */
  
  public function addAlbum($personId, $caption, $private='Everyone', $location=NULL){

  	$REST = "http://opensocial.myspace.com/roa/09/albums/".$personId."/@self/?";
  	$params = NULL;
	$method = 'PUT';
    $privacyValid = array('Everyone','FriendsOnly','Me');
	$isPrivacyValid = false;
	
	foreach($privacyValid as $test){
	  if($test == $privacy) $isPrivacyValid = true;
	}
	
	if($isPrivacyValid == false) {
		  //raise error
	}
    $body = '{"caption":"'.$caption.'","mediaItemCount":"0","location":"'.$location.'","msPrivacyLevel":"'.$privacy.'"}';
	$response = $this->context->makeOAuthRequest(    $REST,
								null,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}

  }
  
  /*
   *  OpenSocial v0.9 Ablums
   *  Resource: http://opensocial.myspace.com/roa/09/albums/@me/@self/{albumId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Albums
   *  Description:  Update the Album
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $albumId       album Id of the album
   *  @param string  $caption	    title of the album
   *  @param string  $location		location of the album
   *  @return object of php object representing the url of the updated album
   */
  
  public function updateAlbum($personId, $albumId, $caption, $location=NULL){

  	$REST = "http://opensocial.myspace.com/roa/09/albums/".$personId."/@self/".$albumId."?";
  	$params = NULL;
	$method = 'POST';
    
    $body = '{"caption":"'.$caption.'","mediaItemCount":"0","location":"'.$location.'"}';
	$response = $this->context->makeOAuthRequest(    $REST,
								null,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Get the Media Items Supported Fields
   *  @return object of php object representing the JSON which is list of supported fields
   */
  
  public function getMediaItemSupportedFields(){
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaItems/@supportedFields?';
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/{albumId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Get the Media Items By AlbumId
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $albumId       album Id of the album
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        set the specific fields here
   *  @return object of php object representing the JSON which is list of the specific user media items
   */
  
  public function getMediaItems($personId, $albumId, $startIndex=1, $count=20, $fields=NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/'.$albumId.'?';
  	
    
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json'
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/{albumId}/{menuItemId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Get the Media Items By Album ID and MenuItemId
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $albumId       album Id of the album
   *  @param mixed   @menuItemId    menuItemId 
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        set the specific fields here
   *  @return object of php object representing the JSON which is list of the specific user media Items
   */
  
  public function getMediaItemById($personId, $albumId, $menuItemId, $startIndex=1, $count=20, $fields=NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaItems/'.$personId.'/@self/'.$albumId.'/'.$menuItemId.'?';
  	
    
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json'
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/{albumId}/
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Add Photo
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $albumId       album Id of the album
   *  @param string  @caption       title of the photo
   *  @param integer $filePath      file path of the photo
   *  @return object of php object representing the url of newly created photo
   */
  
  public function addPhoto($personId, $albumId, $caption, $filePath) {
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaItems/'.$personId.'/@self/'.$albumId.'?';
    $method = 'POST';
    
    $params = array( 
  				'type' => 'IMAGE',
  				'caption' => $caption
  				);
  	
  	$data = file_get_contents($filePath);
  	$body = $data;
  				
	$response = $this->context->makeOAuthRequest($REST,
								$params,
								$method,
								array('Content-Type' => 'image/jpg'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/{albumId}/
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Add Video
   *  @param mixed   $personId      current Person Id
   *  @param string  $caption       title of the video
   *  @param string  $description   description of the video
   *  @param string  $tags			video tags
   *  @param string  $language		language
   *  @param integer $filePath      file path of the video
   *  @return object of php object representing the url of newly created photo
   */
  
  public function addVideo($personId, $caption, $description,  $filePath, $tags=NULL, $msCategories=NULL, $language='en-US') {
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaItems/'.$personId.'/@self/0?';
    $method = 'POST';
    
    $params = array( 
  				'type' => 'VIDEO',
  				'caption' => $caption,
    			'description' => $description,
    			'tags' => $tags,
    			'msCategories' => $msCategories,
    			'language' => $language
  				);
  	
  	$data = file_get_contents($filePath);
  	$body = $data;
  				
	$response = $this->context->makeOAuthRequest($REST,
								$params,
								$method,
								array('Content-Type' => 'video/mpeg'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Get the Videos Supported Categories
   *  @return object of php object representing the JSON which is list of supported fields
   */
  
  public function getVideosCategories($personId){
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaitems/'.$personId.'/@videos/@supportedcategories?'; 
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 MediaItems
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItems/@supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_0.9_MediaItems
   *  Description:  Get the Videos Supported Categories by category Id
   *  @return object of php object representing the JSON which is list of supported fields
   */
  
  public function getVideosCategoriesById($personId, $categoryId){
    $REST  = 'http://opensocial.myspace.com/roa/09/mediaitems/'.$personId.'/@videos/@supportedcategories/'.$categoryId.'?'; 
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 MediaItemComments
   *  Resource: http://opensocial.myspace.com/roa/09/mediaItemcomments/@me/@self/{albumId}/{menuItemId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_MediaItemComments
   *  Description:  Get Media Item Comments
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $albumId       album Id of the album
   *  @param mixed   $menuItem	    specific menuItem Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param integer $filePath      file path of the photo
   *  @return object of php object representing the JSON which is list of the specific user album
   */
  
  public function getMediaItemComments($personId, $albumId, $menuItemId, $startIndex=1, $count=20, $fields=NULL){
     $REST  = 'http://opensocial.myspace.com/roa/09/mediaitemcomments/'.$personId.'/@self/'.$albumId.'/'.$menuItemId.'?';
  	
    
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json'
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  
  
  /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get Activities Supported Fields
   *  @return object of php object representing the JSON which is list of activities supported fields
   */
  
  public function getActivitiesSupportedFields(){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/@supportedFields?';
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@supportedVerbs?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get Activities Supported Verbs
   *  @return object of php object representing the JSON which is list of activities supported verbs
   */
  
  public function getActivitiesSupportedVerbs(){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/@supportedVerbs';
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
  /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@supportedObjectTypes?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get Activities Supported Object
   *  @return object of php object representing the JSON which is list of activities supported object types
   */
  
  public function getActivitiesSupportedTypes(){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/@supportedObjectTypes?';
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');

  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get user Activities
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $updatedSince  Indicates the date before which no activities should be returned
   *  @return object of php object representing the JSON which is list of current user activities
   */
  
   public function getActivities($personId, $startIndex=1, $count=20, $fields=NULL, $updatedSince=NULL){
     $REST  = 'http://opensocial.myspace.com/roa/09/activities/'.$personId.'/@self?';
  	 $params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json',
  				'updatedSince' => $updatedSince
  				);
	
  	 $responseJSON = $this->context->call($REST, $params, 'GET');
  	 return MySpaceUtils::parseJSON($responseJSON);

   }
  
   /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@me/@friends?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get Friend Activities
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $updatedSince  Indicates the date before which no activities should be returned
   *  @return object of php object representing the JSON which is list of current user friend activities
   */
  
  public function getFriendActivities($personId, $startIndex=1, $count=20, $fields=NULL, $updatedSince=NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/'.$personId.'/@friends?';
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json',
  				'updatedSince' => $updatedSince
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@me/@self/{appId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get user Activities by application Id
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $appId         specific application Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $updatedSince  Indicates the date before which no activities should be returned
   *  @return object of php object representing the JSON which is list of current user activities
   */
  
  public function getActivitiesByAppId($personId, $appId, $startIndex=1, $count=20, $fields=NULL, $updatedSince=NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/'.$personId.'/@self/'.$appId.'?';
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json',
  				'updatedSince' => $updatedSince
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@me/@friends/{appId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Get Friend Activities by application Id
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $appId         specific application Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $updatedSince  Indicates the date before which no activities should be returned
   *  @return object of php object representing the JSON which is list of current user friend activities
   */
  
  public function getFriendActivitiesByAppId($personId, $appId, $startIndex=1, $count=20, $fields=NULL, $updatedSince=NULL){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/'.$personId.'/@friends/'.$appId.'?';
  	$params = array( 
  				'count' => (empty($count) ? 20 : $count),
  				'startIndex' => (empty($startIndex) ? 1 : $startIndex),
  				'fields' => '@all',
  				'fields' => $fields,
  				'format' => 'json',
  				'updatedSince' => $updatedSince
  				);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Activities
   *  Resource: http://opensocial.myspace.com/roa/09/activities/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Activities
   *  Description:  Create Activity
   *  @param mixed         $personId         current Person Id
   *  @param mixed         $externalId       external Id
   *  @param integer       $title            title of the activity
   *  @param integer       $body		     body of the activity
   *  @param dictionary    $templateParams   Dictionary parameter
   *  @param string        $titleid          titleId of the activity
   *  @return object of php object representing the url of newly created activity
   */
  
  public function createActivity($personId, $externalId, $title, $body, $templateParams, $titleId){
    $REST  = 'http://opensocial.myspace.com/roa/09/activities/'.$personId.'/@self?';
  
	// Convert templateParameters to a string representation
	$sb = '[';
	$n = count($templateParams);
	$i = 0;
 	foreach ($templateParams as $key => $val) {
 		$sb .= '{"key":"' . $key . '","value":"' . $val . '"}';
 		$i++;
 		if ($i == $n)
 			$sb .= ']';
 		else
 			$sb .= ',';
	} 
	
    $method = 'POST';
    
    $body = '{"externalId":"'.$externalId.'","id":"myspace.com.activity.-1","title":"'.$title.'","body":"'.$body.'","templateParams":{"msParameters":'.$sb.'},"titleId":"'.$titleId.'"}';
	$response = $this->context->makeOAuthRequest(    $REST,
								null,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}


  }
  
   /*
   *  OpenSocial v0.9 AppData
   *  Resource: http://opensocial.myspace.com/roa/09/appdata/@me/@self/{$appId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_AppData
   *  Description:  add/update App Data
   *  @param mixed     $personId         current Person Id
   *  @param mixed     $appId            application Id
   *  @param integer   $key              specific key
   *  @param integer   $value		     specific value
   *  @return object of php object representing the app data
   */
  
  public function addAppData($personId, $appId, $key, $value) {
  	 $REST  = 'http://opensocial.myspace.com/roa/09/appdata/'.$personId.'/@self/'.$appId.'?fields='.$key;
  	 $params = array('fields' => $key);
	 $method = 'POST';
     $body = '{"userId":"'.$personId.'","appData":[{"key":"'.$key.'","value":"'.$value.'"}]}';
	 $response = $this->context->makeOAuthRequest(    $REST,
								NULL,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	 if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	 }
  }
  
   /*
   *  OpenSocial v0.9 AppData
   *  Resource: http://opensocial.myspace.com/roa/09/appdata/@me/@self/{$appId}
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_AppData
   *  Description:  Get App Data
   *  @param mixed     $personId         current Person Id
   *  @param mixed     $appId            application Id
   *  @param integer   $key              specific key
   *  @param integer   $value		     specific value
   *  @return object of php object representing the JSON which is list of app data
   */
  
  public function getAppData($personId, $appId, $key=NULL, $value=NULL) {
  	 $REST  = 'http://opensocial.myspace.com/roa/09/appdata/'.$personId.'/@self/'.$appId.'?';
  	 $params = array('key' => $key);
  	 
	
  	 $responseJSON = $this->context->call($REST, $params, 'GET');
  	 return MySpaceUtils::parseJSON($responseJSON);
  }
  
   /*
   *  OpenSocial v0.9 AppData
   *  Resource: http://opensocial.myspace.com/roa/09/appdata/@me/@self/{$appId}?fields=key
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_AppData
   *  Description:  Delete App Data
   *  @param mixed     $personId         current Person Id
   *  @param mixed     $appId            application Id
   *  @param string    $keys             semicolon separated keys to clear
   *  @return true on success, false on failure
   */
  
  public function clearAppData($personId, $appId, $keys) {
  	$REST = 'http://opensocial.myspace.com/roa/09/appData/'.$personId.'/@self/'.$appId.'?fields='.$keys;
  	$params = array('fields' => $keys);
  	$method = 'DELETE';
    $response = $this->context->makeOAuthRequest(
		  						$REST,
								null,
								$method,
								array('Content-Type' => 'application/x-www-form-urlencoded'),
								$body
								);
	  if($response['status']== 200|201 ){
		  return true;
	  }
  }
  
  
   /*
   *  OpenSocial v0.9 Groups
   *  Resource: http://opensocial.myspace.com/roa/09/groups/@me?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Groups
   *  Description:  Get Groups
   *  @param mixed     $personId         current Person Id
   *  @return object of php object representing the JSON which is list of current user groups
   */
  
  public function getGroups($personId){

  	$REST = "http://opensocial.myspace.com/roa/09/groups/".$personId.'?';
  	$params = array('format'=>'json', 'fields'=>'@all', 'fields'=>$fields);
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Groups
   *  Resource: http://opensocial.myspace.com/roa/09/groups/supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Groups
   *  Description:  Get Groups Supported Fields
   *  @return object of php object representing the JSON which is list of groups supported fields
   */
  
  public function getGroupsSupportedFields(){

  	$REST = "http://opensocial.myspace.com/roa/09/groups/@supportedFields?";
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 People
   *  Resource: http://opensocial.myspace.com/roa/09/people/supportedFields?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_People
   *  Description:  Get People Supported Fields
   *  @return object of php object representing the JSON which is list of people supported fields
   */
  
  public function getPeopleSupportedFields(){

  	$REST = "http://opensocial.myspace.com/roa/09/people/@supportedFields?";
  	$params = array('format'=>'json');
	
  	$responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 People
   *  Resource: http://opensocial.myspace.com/roa/09/people/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_People
   *  Description:  Get People
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $filterby      some valid values : {topFriends | toponlineFriends | hasApp etc }
   *  @param string  $filterop      some valid values : {contains | equals etc }
   *  @param string  $filtervalue   some valid values : {true | false | specific value etc }
   *  @return object of php object representing the JSON of people
   */
  
  public function getPerson($personId, $fields=NULL, $startePage=1, $count=20, $filterby=NULL, $filterop=NULL, $filtervalue=NULL) {

  	$REST = "http://opensocial.myspace.com/roa/09/people/".$personId."/@self?";
  	$params = array('format'=>'json', 
  	   				'fields'=>'@all', 
  	   				'fields'=>$fields,
  	  				'filterby' => $filterby,
  	  				'filterop' => $filterop,
  	  				'filtervalue' => $filtervalue,
  	  				'count' => (empty($count) ? 20 : $count),
  	  				'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 People
   *  Resource: http://opensocial.myspace.com/roa/09/people/@me/@friends?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_People
   *  Description:  Get Friends
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $filterby      some valid values : {topFriends | toponlineFriends | hasApp etc }
   *  @param string  $filterop      some valid values : {contains | equals etc }
   *  @param string  $filtervalue   some valid values : {true | false | specific value etc }
   *  @return object of php object representing the JSON in which a list of current user friends
   */
  
  public function getFriends($personId, $fields=NULL, $startePage=1, $count=20, $filterby=NULL, $filterop=NULL, $filtervalue=NULL) {

  	$REST = "http://opensocial.myspace.com/roa/09/people/".$personId."/@friends?";
  	$params = array('format'=>'json', 
  	   				'fields'=>'@all', 
  	   				'fields'=>$fields,
  	  				'filterby' => $filterby,
  	  				'filterop' => $filterop,
  	  				'filtervalue' => $filtervalue,
  	  				'count' => (empty($count) ? 20 : $count),
  	  				'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 People
   *  Resource: http://opensocial.myspace.com/roa/09/people/@me/{groupId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_People
   *  Description:  Get People By Group Id
   *  @param mixed   $personId      current Person Id
   *  @param mixed   $groupId       group Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $filterby      some valid values : {topFriends | toponlineFriends | hasApp etc }
   *  @param string  $filterop      some valid values : {contains | equals etc }
   *  @param string  $filtervalue   some valid values : {true | false | specific value etc }
   *  @return object of php object representing the JSON in which a list of current people by group Id
   */
  
  public function getPeopleByGroupId($personId, $groupId, $fields=NULL, $startePage=1, $count=20, $filterby=NULL, $filterop=NULL, $filtervalue=NULL) {

  	$REST = "http://opensocial.myspace.com/roa/09/people/".$personId."/".$groupId."?";
  	$params = array('format'=>'json', 
  	   				'fields'=>'@all', 
  	   				'fields'=>$fields,
  	  				'filterby' => $filterby,
  	  				'filterop' => $filterop,
  	  				'filtervalue' => $filtervalue,
  	  				'count' => (empty($count) ? 20 : $count),
  	  				'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  OpenSocial v0.9 Notification
   *  Resource: http://opensocial.myspace.com/roa/09/notifications/@me/@self/?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_Notifications
   *  Description:  Send notification
   *  @param mixed         $personId         current Person Id
   *  @param mixed         $recipientIds     comma seperated receipient Ids
   *  @param dictionary    $templateParams   dictionary parameter
   *  @param mixed         $mediaItems       media item uri  
   *  @return object of php object representing the JSON in which a list of current media item comments
   */

   public function sendNotification($personId, $recipientIds, $templateParams, $mediaItems) {
	if ($templateParams['content'] == null)
		throw new MySpaceException('\'content\' key required in templateParameters Map');

	// Convert templateParameters to a string representation
	$sb = '[';
	$n = count($templateParams);
	$i = 0;
 	foreach ($templateParams as $key => $val) {
 		$sb .= '{"key":"' . $key . '","value":"' . $val . '"}';
 		$i++;
 		if ($i == $n)
 			$sb .= ']';
 		else
 			$sb .= ',';
	} 
	
	
	$body = '{"mediaItems":[{"msMediaItemUri":"'.$mediaItem.'"}],"recipientIds":["'.$recipientIds.'"], "templateParameters":'.$sb.'}';

	$REST = 'http://opensocial.myspace.com/roa/09/notifications/'.$personId.'/@self?';
	$method = 'POST';
	// Send request
    $response = $this->context->makeOAuthRequest($REST,
								null,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	  if($response['status']== 200|201 ){
		  return MySpaceUtils::parseJSON($response['body']);
	  }
  }
  
   /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Update Status
   *  @param mixed   $personId         current Person Id
   *  @param mixed   $moodName         mood name like excited
   *  @param integer $mediaItem        mediaItem Id
   *  @param string  $status           status message
   *  @param string  $currentLocaiton  specify location
   *  @return object of php object representing the url of newly created status mood
   */
  
	public function updateStatus($personId, $moodName, $status, $currentLocation){

	  $REST = 'http://opensocial.myspace.com/roa/09/statusmood/'.$personId.'/@self?';
	  $method = 'PUT';
	  $sb = '{';
	  $n = count($currentLocation);
	  $i = 0;
	  
 	  foreach ($currentLocation as $key => $val) {
 		 $sb .= '"' . $key . '":"' . $val . '"';
 		 $i++;
 		 if ($i == $n)
 			$sb .= '}';
 		 else
 			$sb .= ',';
 	  }
 	   
	  $mood = '{"moodName":"'.$moodName.'","status":"'.$status.'","currentLocation":'.$sb.'}';
	  $body = $mood;
	  $response = $this->context->makeOAuthRequest(    $REST,
								null,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	  if($response['status']== 200|201 ){
		  return MySpaceUtils::parseJSON($response['body']);
	  }
  	
    }

    
   /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get StatusMood
   *  @param mixed   $personId         current Person Id
   *  @param mixed   $fields           specific fields
   *  @return object of php object representing the JSON in which the current status mood
   */

    public function getStatus($personId, $fields=NULL) {

  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@self?";
  	  $params = array('format'=>'json', 'fields'=>'@all', 'fields'=>$fields);
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
   /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@self/history?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get StatusMood History
   *  @param mixed   $personId         current Person Id
   *  @param mixed   $fields           specific fields
   *  @return object of php object representing the JSON in which the list of status moods
   */

    public function getStatusHistory($personId, $fields=NULL) {
  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@self/history?";

  	  $params = array('format'=>'json', 'fields'=>'@all', 'fields'=>$fields);
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
   /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@friends/history?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get StatusMood History
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $fields        specific fields
   *  @param string  $filterby      some valid values : {topFriends | toponlineFriends | hasApp etc }
   *  @param string  $filterop      some valid values : {contains | equals etc }
   *  @param string  $filtervalue   some valid values : {true | false | specific value etc }
   *  @param bool    $includeself   current user should included or not
   *  @return object of php object representing the JSON in which the list of friends status moods
   */

    public function getFriendsStatusHistory($personId, $startePage=1, $count=20,$fields=NULL, $filterby=NULL, $filterop=NULL, $filtervalue=NULL, $includeself=NULL) {
  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@friends/history?";
  	  $params = array('format'=>'json', 
  	   				  'fields'=>'@all', 
  	   				  'fields'=>$fields,
  	  				  'filterby' => $filterby,
  	  				  'filterop' => $filterop,
  	  				  'filtervalue' => $filtervalue,
  	  				  'includeself' => $includeself,
  	  				  'count' => (empty($count) ? 20 : $count),
  	  				  'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
   /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@all/{friendId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get Friend StatusMood
   *  @param mixed   $personId      current Person Id
   *  @param integer $friendId      friend Id
   *  @param string  $fields        specific fields
   *  @return object of php object representing the JSON in which the friend status moods
   */
   
    public function getFriendsStatus($personId, $friendId, $fields=NULL) {
  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@friends/".$friendId."?";
  	  $params = array('format'=>'json', 
  	   				  'fields'=>'@all', 
  	   				  'fields'=>$fields);
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
  /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@all/{friendId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get Friend StatusMood History
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param integer $friendId      friend id
   *  @param string  $fields        specific fields
   *  @return object of php object representing the JSON in which the friend status mood history
   */
   
    public function getFriendStatusHistory($personId, $friendId, $startIndex=1, $count=20, $fields=NULL) {
  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@friends/".$friendId."/history?";
  	  $params = array('format'=>'json', 
  	   				  'fields'=>'@all', 
  	   				  'fields'=>$fields,
  	  				  'count' => (empty($count) ? 20 : $count),
  	  				  'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
  /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@supportedMood/{moodId}?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get  Supported StatusMood By Mood
   *  @param mixed   $personId      current Person Id
   *  @param integer $moodId	    mood Id
   *  @return object of php object representing the JSON in which the supported mood
   */
  
    public function getSupportedStatusById($personId, $moodId){

  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@supportedMood/".$moodId."?";
  	  $params = array('format'=>'json');
	  
  	  $responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }

  /*
   *  OpenSocial v0.9 StatusMood
   *  Resource: http://opensocial.myspace.com/roa/09/statusmood/@me/@supportedMood?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMood
   *  Description: Get  All Supported Mood
   *  @param mixed   $personId      current Person Id
   *  @return object of php object representing the JSON in which the list of all supported mood
   */

   public function getSupportedStatus($personId) {

  	  $REST = "http://opensocial.myspace.com/roa/09/statusmood/".$personId."/@supportedMood?";
   	  $params = NULL;
	
  	  $responseJSON = $this->context->call_JSONArray($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
  /*
   *  OpenSocial v0.9 StatusMoodComments
   *  Resource: http://opensocial.myspace.com/roa/09/statusmoodcomments/@me/@supportedMood?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMoodComments
   *  Description: Get Status Mood Comments
   *  @param mixed   $personId      current Person Id
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @return object of php object representing the JSON in which the list of all supported mood comments
   */
   
   public function getStatusMoodComments($personId, $statusId, $startePage=1, $count=20, $fields=NULL) {
  	  $REST = "http://opensocial.myspace.com/roa/09/statusmoodcomments/".$personId."/@self?";
  	  $params = array('format'=>'json', 
  	  				  'statusId'=>$statusId,
  	   				  'fields'=>'@all', 
  	   				  'fields'=>$fields,
  	  				  'count' => (empty($count) ? 20 : $count),
  	  				  'startPage' => (empty($startPage) ? 1 : $startPage));
	
  	  $responseJSON = $this->context->call($REST, $params, 'GET');
  	  //parseJSON is a static method and does not effect the object
  	  return MySpaceUtils::parseJSON($responseJSON);
   }
   
  /*
   *  OpenSocial v0.9 StatusMoodComments
   *  Resource: http://opensocial.myspace.com/roa/09/statusmoodcomments/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMoodComments
   *  Description: Add Status Mood Comments
   *  @param mixed   $personId      current Person Id
   *  @param integer $statusId      Status Id
   *  @param integer $comment		comment
   *  @return object of php object representing the url of newly created statusmood comments
   */
   
   public function addStatusMoodCommentById($personId, $statusId, $comment) {
  	 $REST = "http://opensocial.myspace.com/roa/09/statusmoodcomments/333220680/@self?";
	 $params = array( 
  				'statusId' => $statusId
  				);
  	 	
	$method = 'POST';
    $body = '{"body":"'.$comment.'"}';
	$response = $this->context->makeOAuthRequest(    $REST,
								$params,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}
   }
  
  /*
   *  OpenSocial v0.9 StatusMoodComments
   *  Resource: http://opensocial.myspace.com/roa/09/statusmoodcomments/@me/@self?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=OpenSocial_v0.9_StatusMoodComments
   *  Description: Add Status Mood Comments By Id
   *  @param mixed   $personId      current Person Id
   *  @param integer $postedDate    mood Posted Date
   *  @param integer $comment		comment
   *  @return object of php object representing the url of newly created statusmood comments
   */
   
   public function addStatusMoodCommentByDate($personId, $postedDate, $comment) {
  	 $REST = "http://opensocial.myspace.com/roa/09/statusmoodcomments/".$personId."/@self?";
  	 $params = array( 
  				'format' => 'json',
  	 			'postedDate' => $postedDate
  				);
	$method = 'POST';
    $body = '{"body":"'.$comment.'",}';
	$response = $this->context->makeOAuthRequest(    $REST,
								$params,
								$method,
								array('Content-Type' => 'application/json'),
								$body
								);
        
	if($response['status']== 200|201 ){
		 return MySpaceUtils::parseJSON($response['body']);
	}
   }
}

?>